#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

void *FunTest( void *arg )
{
    int iCnt=0;
    pthread_t *ptidFunMain = arg;

    
    while (1)
    {
        if( iCnt == 3 )
        {
            pthread_cancel( *ptidFunMain );            
        }

        printf("Thread Sub  %d\n", iCnt );

        iCnt++;
        sleep(2);

    }
}

int main(int argc, char const *argv[])
{
    pthread_t tidFunTest;
    pthread_t tidFunMain = pthread_self();
    
    int iCnt = 0;

    pthread_create( &tidFunTest, NULL, FunTest, &tidFunMain );

    while(1)
    {
        if( iCnt == 4 )
        {
            pthread_cancel( tidFunTest );            
        }

        printf( "Thread main %d\n", iCnt );
        
        iCnt++;
        sleep(2);
    }

    return 0;
}

/*
函数 pthread_cancel
可以互相杀死

*/